// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

#nullable restore

using Elastic.Clients.Elasticsearch.Serverless.Fluent;
using Elastic.Clients.Elasticsearch.Serverless.Serialization;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Elastic.Clients.Elasticsearch.Serverless.Analysis;

public sealed partial class StopTokenFilter : ITokenFilter
{
	[JsonInclude, JsonPropertyName("ignore_case")]
	public bool? IgnoreCase { get; set; }
	[JsonInclude, JsonPropertyName("remove_trailing")]
	public bool? RemoveTrailing { get; set; }
	[JsonInclude, JsonPropertyName("stopwords")]
	[SingleOrManyCollectionConverter(typeof(string))]
	public ICollection<string>? Stopwords { get; set; }
	[JsonInclude, JsonPropertyName("stopwords_path")]
	public string? StopwordsPath { get; set; }

	[JsonInclude, JsonPropertyName("type")]
	public string Type => "stop";

	[JsonInclude, JsonPropertyName("version")]
	public string? Version { get; set; }
}

public sealed partial class StopTokenFilterDescriptor : SerializableDescriptor<StopTokenFilterDescriptor>, IBuildableDescriptor<StopTokenFilter>
{
	internal StopTokenFilterDescriptor(Action<StopTokenFilterDescriptor> configure) => configure.Invoke(this);

	public StopTokenFilterDescriptor() : base()
	{
	}

	private bool? IgnoreCaseValue { get; set; }
	private bool? RemoveTrailingValue { get; set; }
	private ICollection<string>? StopwordsValue { get; set; }
	private string? StopwordsPathValue { get; set; }
	private string? VersionValue { get; set; }

	public StopTokenFilterDescriptor IgnoreCase(bool? ignoreCase = true)
	{
		IgnoreCaseValue = ignoreCase;
		return Self;
	}

	public StopTokenFilterDescriptor RemoveTrailing(bool? removeTrailing = true)
	{
		RemoveTrailingValue = removeTrailing;
		return Self;
	}

	public StopTokenFilterDescriptor Stopwords(ICollection<string>? stopwords)
	{
		StopwordsValue = stopwords;
		return Self;
	}

	public StopTokenFilterDescriptor StopwordsPath(string? stopwordsPath)
	{
		StopwordsPathValue = stopwordsPath;
		return Self;
	}

	public StopTokenFilterDescriptor Version(string? version)
	{
		VersionValue = version;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (IgnoreCaseValue.HasValue)
		{
			writer.WritePropertyName("ignore_case");
			writer.WriteBooleanValue(IgnoreCaseValue.Value);
		}

		if (RemoveTrailingValue.HasValue)
		{
			writer.WritePropertyName("remove_trailing");
			writer.WriteBooleanValue(RemoveTrailingValue.Value);
		}

		if (StopwordsValue is not null)
		{
			writer.WritePropertyName("stopwords");
			SingleOrManySerializationHelper.Serialize<string>(StopwordsValue, writer, options);
		}

		if (!string.IsNullOrEmpty(StopwordsPathValue))
		{
			writer.WritePropertyName("stopwords_path");
			writer.WriteStringValue(StopwordsPathValue);
		}

		writer.WritePropertyName("type");
		writer.WriteStringValue("stop");
		if (!string.IsNullOrEmpty(VersionValue))
		{
			writer.WritePropertyName("version");
			writer.WriteStringValue(VersionValue);
		}

		writer.WriteEndObject();
	}

	StopTokenFilter IBuildableDescriptor<StopTokenFilter>.Build() => new()
	{
		IgnoreCase = IgnoreCaseValue,
		RemoveTrailing = RemoveTrailingValue,
		Stopwords = StopwordsValue,
		StopwordsPath = StopwordsPathValue,
		Version = VersionValue
	};
}